use crate::memory::{MemErrors, MemResult};

/// 创建连续空间 size为空间大小 单位为 byte 返回起始地址
/// 当创建失败的时候会恐慌
pub fn create_mem_space(size: usize) -> MemResult<usize> {
    let start = unsafe { libc::calloc(size, 1) } as usize;
    if start == 0 {
        Err(MemErrors::MemoryCreateFailure)
    } else {
        Ok(start)
    }
}

/// 删除动态分配的内存空间 address 为空间的地址/起始地址
pub fn delete_mem_space(address: usize) {
    unsafe {
        let ptr = address as *mut libc::c_void;
        libc::free(ptr);
    }
}

#[cfg(test)]
mod tests {}